package com.bawei.property.view

import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.RoutePath
import com.bawei.common.base.BaseActivity
import com.bawei.property.R
import com.bawei.property.databinding.ActivityPropertyBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = RoutePath.PATH_PROPERTY_PAGE)
@AndroidEntryPoint
class PropertyActivity : BaseActivity<ActivityPropertyBinding>() {

    @Autowired
    @JvmField
    var moduleType: String = "1"

    override fun getLayoutId(): Int = R.layout.activity_property

    override fun initViews() {
        ARouter.getInstance().inject(this)
        initModuleFragment()
        //返回点击事件
        mDataBinding.includePageTitle.ivBack.setOnClickListener {
            this@PropertyActivity.finish()
        }
    }


    private fun initModuleFragment(){
        when(moduleType){
            "1" -> {
                mDataBinding.includePageTitle.tvTitle.text = "车位申请"
                commitFragment(ParkApplyFragment.newInstance(), moduleType)
            }
            "2" -> {
                mDataBinding.includePageTitle.tvTitle.text = "我的申请"
                commitFragment(MineApplyFragment.newInstance(), moduleType)
            }
            "3" -> {
                mDataBinding.includePageTitle.tvTitle.text = "来访预约"
                commitFragment(AppointmentFragment.newInstance(), moduleType)
            }
            "4" -> {
                mDataBinding.includePageTitle.tvTitle.text = "巡更管理"
                commitFragment(PatrolFragment.newInstance(), moduleType)
            }
            "5" -> {
                mDataBinding.includePageTitle.tvTitle.text = "维修管理"
                commitFragment(MaintenanceFragment.newInstance(), moduleType)
            }
            "6" -> {
                mDataBinding.includePageTitle.tvTitle.text = "添加维修"
                commitFragment(AddMaintenanceFragment.newInstance(), moduleType)
            }
        }
    }

    /**
     * 提交Fragment到当前Activity
     */
    private fun commitFragment(moduleFragment: Fragment, fragmentTag: String){
        //1.获取FragmentManager对象
        var fm = supportFragmentManager
        //2.开启事务
        var fragmentTransaction = fm.beginTransaction()
        //3.提交事务
        fragmentTransaction.replace(R.id.fragment_container, moduleFragment, fragmentTag)
        fragmentTransaction.commit()
    }



}